home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / cenvid.zip / PATHADD.BAT < prev    next >
DOS Batch File  |  1993-03-20  |  1KB  |  45 lines

  1. @echo off
  2. REM PathAdd.bat - add a directory to the current path, if it's not already there
  3. if "%1"=="" GOTO SHOW_HOW
  4. if not "%2"=="" GOTO SHOW_HOW
  5. cenvi %0.BAT %1
  6. GOTO FINI
  7.  
  8. :SHOW_HOW
  9. ECHO PathAdd.bat - Add a directory to the PATH if it's not already there
  10. ECHO USAGE: PathBat DirSpec
  11. GOTO FINI
  12.  
  13.  
  14. GOTO CENVI_EXIT
  15.  
  16. main(argc,argv)
  17. {
  18.    NewDir = argv[1]
  19.    if ( AlreadyInPath(NewDir) ) {
  20.       printf("The Directory \"%s\" is already in PATH.\n",NewDir)
  21.    } else {
  22.       // File is not already in the path, and so append to the end of PATH.
  23.       // If there isn't a semi-colon at the end of PATH already, then add one.
  24.       if ( PATH[strlen(PATH)-1] != ';' )
  25.          strcat(PATH,";")
  26.       // Append this new directory to the end of the path statement
  27.       strcat(PATH,NewDir)
  28.    }
  29. }
  30.  
  31. AlreadyInPath(Dir) // search through path for this Dir, return True if found, else False
  32. {
  33.    len = strlen(Dir)
  34.    p = PATH
  35.    do {
  36.       if ( 0 == strnicmp(p,Dir,len)  && (p[len]==0 || p[len]==';') )
  37.          return(True)
  38.       p = strchr(p,';')
  39.    } while( p++ != NULL )
  40.    return(False)
  41. }
  42.  
  43. :CENVI_EXIT
  44. :FINI
  45.